import os
import string

def findFile(root_dir,filetype):
    for root, dirs, files in os.walk(root_dir):
        for file in files:
            if os.path.splitext(file)[1] in filetype:
                all_files.append(os.path.join(root,file))

if __name__ == "__main__":
    current_dir = 'E:\深度学习\machine_learning\machinelearning_homework\homework_01_python'
    target_filetype = ('.c','.cpp','.py','.jsp','.js')
    all_files = []
    findFile(current_dir,target_filetype)
    code_lines = {'.c':0,'.cpp':0,'.py':0,'.jsp':0,'.js':0}
    for file in all_files:
        with open(file,'r') as f:
            lines = f.readlines()
            cnt = 0
            for line in lines:
                cnt+=1
        fi = str(file)
        print(fi.replace(current_dir,''),' ',cnt)
        code_lines[os.path.splitext(file)[1]] += cnt
    for key in code_lines.keys():
        print("\n'{}' code has {} lines".format(key,code_lines[key]))
 